package com.hzvictory.hotel_system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
//import org.springframework.security.access.prepost.PreAuthorize;
import com.hzvictory.hotel_system.pojo.entity.Dishorder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hzvictory.hotel_system.common.annotation.Log;
import com.hzvictory.hotel_system.common.core.controller.BaseController;
import com.hzvictory.hotel_system.common.core.domain.AjaxResult;
import com.hzvictory.hotel_system.common.enums.BusinessType;
import com.hzvictory.hotel_system.pojo.entity.Dishcart;
import com.hzvictory.hotel_system.service.IDishcartService;
//import com.hzvictory.hotel_system.common.utils.ExcelUtil;
import com.hzvictory.hotel_system.common.core.page.TableDataInfo;

/**
 * 购物车管理Controller
 *
 * @author hzvictory
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/system/dishcart")
public class DishcartController extends BaseController
{
    @Autowired
    private IDishcartService dishcartService;

    /**
     * 查询购物车管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:dishcart:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dishcart dishcart)
    {
        startPage();
        List<Dishcart> list = dishcartService.selectDishcartList(dishcart);
        return getDataTable(list);
    }
    /**
     * 根据用户id查询购物车管理列表
     */
    @GetMapping("/list/{userId}")
    public TableDataInfo getListByUserId(@PathVariable("userId") Long userId)
    {
        startPage();
        List<Dishcart> list = dishcartService.selectDishcartListByUserId(userId);
        return getDataTable(list);
    }

    /**
     * 导出购物车管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:dishcart:export')")
//    @Log(title = "购物车管理", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Dishcart dishcart)
//    {
//        List<Dishcart> list = dishcartService.selectDishcartList(dishcart);
//        ExcelUtil<Dishcart> util = new ExcelUtil<Dishcart>(Dishcart.class);
//        util.exportExcel(response, list, "购物车管理数据");
//    }

    /**
     * 获取购物车管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:dishcart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dishcartService.selectDishcartById(id));
    }

    /**
     * 新增购物车管理
     */
    //@PreAuthorize("@ss.hasPermi('system:dishcart:add')")
    @Log(title = "购物车管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dishcart dishcart)
    {
        return toAjax(dishcartService.insertDishcart(dishcart));
    }

    /**
     * 修改购物车管理
     */
    //@PreAuthorize("@ss.hasPermi('system:dishcart:edit')")
    @Log(title = "购物车管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dishcart dishcart)
    {
        return toAjax(dishcartService.updateDishcart(dishcart));
    }

    /**
     * 删除购物车管理
     */
    //@PreAuthorize("@ss.hasPermi('system:dishcart:remove')")
    @Log(title = "购物车管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dishcartService.deleteDishcartByIds(ids));
    }
    /**
     * 删除某用户购物车的全部数据
     */
    //@PreAuthorize("@ss.hasPermi('system:dishcart:remove')")
    @Log(title = "购物车管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/clear/{userId}")
    public AjaxResult clearDishCartByUserId(@PathVariable("userId") Long userId)
    {
        return toAjax(dishcartService.clearDishCartByUserId(userId));
    }
}
